home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
adir2cnc.zip
/
ADI2CNC.BAS
< prev
next >
Wrap
BASIC Source File
|
1990-11-27
|
11KB
|
495 lines
' quick basic program to convert apple plotter commands
' from autocad adi plotter file into G codes for use with
' CNC milling machine
'
' written by george mcduffee at allen county community college
' march 13th, 1990
' and released to the public domain.
'
' program recognizes the following however other ADI commands can be added
' if required.
'
' 2 = home
' G90
' G00/000/000/000
'
' 3 = move absolute [pen up]
' G91
' G01 000/000/0010
' G90
' G00 X/Y/Z
' G91
' G00 000/000/-010
'
' 4 = plot absolute [pen down]
' G91 X/Y/Z
'
' exact conversion values will depend on how adi plotter selection
' is set up. This program assumes 254 points to the inch horz and vert.
'
' Plot limits assumed to be within CNC limits - 7.87 in [200 m/m] X
' 3.94 in [100 m/m] for Emco F1-CNC machine.
'
' -------- start of program -------------
OPTION BASE 1
DEFINT A-Z
CLS
LOCATE 10, 10
PRINT "This program will convert a AutoCadd ADI plotter output file"
LOCATE 11, 10
PRINT "into CNC G codes. It assumes plot done at 1[inch] = 1[inch] and"
LOCATE 12, 10
PRINT "plot size limited to 7.87 inches in the X direction and 3.94 inches"
LOCATE 13, 10
PRINT "in the Y direction and that only ADI commands 2/3/4 [home/move abs/"
LOCATE 14, 10
PRINT "plot abs are used. Output will be written to <INFILE>.CNC"
LOCATE 16, 10
INPUT "input name of plot file"; plotfile$
' ---------------- OPEN FILES --------------------------
plotfile$ = LTRIM$(RTRIM$(plotfile$))
temp = INSTR(plotfile$, ".")
IF (temp = 0) THEN
plotfile$ = plotfile$ + ".plt"
END IF
OPEN plotfile$ FOR INPUT ACCESS READ AS #1 LEN = 16284
temp = INSTR(plotfile$, ".")
IF temp = 0 THEN
gcodefile$ = plotfile$ + ".cnc"
ELSE
gcodefile$ = LEFT$(plotfile$, (temp - 1))
gcodefile$ = gcodefile$ + ".cnc"
END IF
OPEN gcodefile$ FOR OUTPUT ACCESS WRITE AS #2 LEN = 16284
' ----------------- DIM VARIABLES -----------------------
DIM comma(4) AS INTEGER
DIM InLineCounter AS INTEGER
' Emco F1 omits decimal point
' i.e. "0050" is 0.050
CONST clearence = " 150"
' feed is in 1/10 inches per min.
' i.e. "020" = 2 inches per min.
CONST Feed = " 20"
' factor to convert ADI values to CNC values
' in this case 0.1 M/M to .001 inches
CONST ConversionFactor# = .254
' emco F1-CNC controller requires information in specific column format
DIM HeaderLine1 AS STRING * 4
HeaderLine1 = CHR$(255) + CHR$(255) + CHR$(255) + "%"
DIM HeaderLine2 AS STRING * 30
HeaderLine2 = " N` G` X ` Y ` Z ` F "
DIM LastLine AS STRING
LastLine = " " + CHR$(34) + "I": 'this is > "I< indicating inch Vertical
LastLine = LastLine + CHR$(16) + CHR$(16) + CHR$(16) + CHR$(16) + CHR$(16)
LastLine = LastLine + CHR$(16) + CHR$(16) + CHR$(16) + CHR$(16) + CHR$(16)
CONST FeedRate = " 10"
TYPE EmcoLine
filler AS STRING * 3
BlockNo AS STRING * 3
Gcode AS STRING * 3
CNCx AS STRING * 6
CNCy AS STRING * 5
CNCz AS STRING * 6
Feed AS STRING * 4
END TYPE
DIM emco AS EmcoLine
emco.filler = " "
emco.BlockNo = "000"
emco.Gcode = " 21"
emco.CNCx = " 00"
emco.CNCy = " 00"
emco.CNCz = " 00"
emco.Feed = " "
DIM blankemco AS EmcoLine
blankemco.filler = " "
blankemco.Gcode = " "
blankemco.CNCx = " "
blankemco.CNCy = " "
blankemco.CNCz = " "
blankemco.Feed = " "
emco = blankemco
DIM OldCNCx AS STRING * 6
OldCNCx = " 00"
DIM OldCNCy AS STRING * 5
OldCNCy = " 00"
DIM OldCNCz AS STRING * 6
OldCNCz = " 00"
DIM blank6 AS STRING * 6
blank6 = " "
DIM blank5 AS STRING * 5
blank5 = " "
DIM blank4 AS STRING * 4
blank4 = " "
DIM blank3 AS STRING * 3
blank3 = " "
DIM tempd AS DOUBLE
DIM pc, px, py AS DOUBLE
TYPE emcostring
es1 AS STRING * 30
END TYPE
DIM es AS emcostring
' ----------------- START OF MAIN -----------------------
' send header lines to cnc file
PRINT #2, HeaderLine1
PRINT #2, HeaderLine2
linecount = -1
' set cnc to absolute mode
emco = blankemco
GOSUB MakeNstring
emco.BlockNo = Nstring$
emco.Gcode = " 90"
PRINT #2, emco.filler; emco.BlockNo; emco.Gcode; emco.CNCx; emco.CNCy; emco.CNCz; emco.Feed
WHILE NOT (EOF(1))
LINE INPUT #1, PlotterLine$
' for debug
' PRINT PlotterLine$
GOSUB Convert2CNC
WEND
' write M30 as last line of cnc file
GOSUB MakeNstring
emco = blankemco
emco.BlockNo = Nstring$
emco.Gcode = "M30": 'rapid traverse
emco.CNCx = " "
emco.CNCy = " "
emco.CNCz = " "
PRINT #2, emco.filler; emco.BlockNo; emco.Gcode; emco.CNCx; emco.CNCy; emco.CNCz; emco.Feed
' add lst line
PRINT #2, LastLine
' PRINT #2, ""
CLOSE
' display warning if block count greater than F1-CNC limits
IF linecount > 221 THEN
CLS
LOCATE 10, 10
PRINT "WARNING"
LOCATE 12, 10
PRINT "Generated program contains "; linecount; " blocks"
LOCATE 14, 10
PRINT "The limit of the EMCO controller is 221."
LOCATE 16, 10
PRINT "DATA is usable -- edit and run as two programs"
END IF
END
' -------------------- END OF MAIN -----------------------
' -----------
Convert2CNC:
' set px and py [plotter x and plotter y to -1
' if -1 shows these were not set and error if not 'home'
pc = -1
px = -1
py = -1
' parse plotter line and check data format
'count the number of commas in plotter line assume 2 max but check for
' three for error condition
comma(1) = 0
comma(2) = 0
comma(3) = 0
'increment plotter input file line counter for error reporting
InLineCounter = InLineCounter + 1
comma(1) = INSTR(PlotterLine$, ",")
IF comma(1) > 0 THEN
comma(2) = INSTR(comma(1) + 1, PlotterLine$, ",")
END IF
IF comma(2) > 0 THEN
comma(3) = INSTR(comma(2) + 1, PlotterLine$, ",")
END IF
' for debug
' PRINT "In Line = "; InLineCounter
' PRINT "comma(1) = "; comma(1)
' PRINT "comma(2) = "; comma(2)
' PRINT "comma(3) = "; comma(3)
IF comma(3) > 0 THEN
CLS
LOCATE 5, 10
PRINT "error condition in input file at line "; InLineCounter
LOCATE 7, 10
PRINT "More than 2 commas found. "
LOCATE 9, 10
PRINT "correct input [plotter] file and rerun. Press [Enter] key to exit."
INPUT ; "", dummy$
END
END IF
IF comma(1) = 0 THEN
pc = VAL(PlotterLine$)
ELSE
IF comma(2) = 0 THEN
'error as line must have no or two commas
CLS
LOCATE 5, 10
PRINT "error condition in input file at line "; InLineCounter
LOCATE 7, 10
PRINT "Only 1 comma found. Line must have no or two commas"
LOCATE 9, 10
PRINT "correct input [plotter] file and rerun. Press [Enter] key to exit."
INPUT ; "", dummy$
END
END IF
pc = VAL(PlotterLine$)
temp$ = MID$(PlotterLine$, comma(1) + 1, (comma(2) - comma(1) - 1))
px = VAL(temp$)
temp$ = MID$(PlotterLine$, comma(2) + 1)
py = VAL(temp$)
END IF
' debug
' PRINT "pc ="; pc
' PRINT "px ="; px
' PRINT "py ="; py
GOSUB WriteGCode
RETURN
' -----------
' -----------
WriteGCode:
' px and py from plotter file are in .1 M/M
' save existing CNC x/y/z values for possible later use to withdraw cutter
' without setting to relative mode and then back [saves blocks]
IF NOT emco.CNCx = " " THEN
OldCNCx = emco.CNCx
END IF
IF NOT emco.CNCy = " " THEN
OldCNCy = emco.CNCy
END IF
IF NOT emco.CNCz = " " THEN
OldCNCz = emco.CNCz
END IF
' move absolute pen up
IF (pc = 3) THEN GOSUB MoveCutterUp
'move absolute pen down
IF pc = 4 THEN GOSUB MillLine
' home
IF (pc = 2 AND px = -1 AND py = -1) THEN GOSUB Home
RETURN
' --------------
' -------------
MakeNstring:
linecount = linecount + 1
n$ = STR$(linecount)
n$ = RTRIM$(LTRIM$(n$))
SELECT CASE LEN(n$)
CASE IS = 1
Nstring$ = "00" + n$
CASE IS = 2
Nstring$ = "0" + n$
CASE IS = 3
Nstring$ = n$
CASE ELSE
END SELECT
RETURN
' ----------
' ---------- homes the head
Home:
'withdraw cutter under rapid traverse
GOSUB MakeNstring
emco = blankemco
emco.BlockNo = Nstring$
emco.Gcode = " 00": 'rapid traverse
emco.CNCx = OldCNCx
emco.CNCy = OldCNCy
emco.CNCz = " 00"
PRINT #2, emco.filler; emco.BlockNo; emco.Gcode; emco.CNCx; emco.CNCy; emco.CNCz; emco.Feed
' move to home under rapid traverse
GOSUB MakeNstring
emco = blankemco
emco.BlockNo = Nstring$
emco.Gcode = " 00": 'rapid traverse
emco.CNCx = " 00"
emco.CNCy = " 00"
emco.CNCz = " 00"
PRINT #2, emco.filler; emco.BlockNo; emco.Gcode; emco.CNCx; emco.CNCy; emco.CNCz; emco.Feed
RETURN
' -----------
' ----------
MoveCutterUp:
' withdraw cutter at rapid traverse
GOSUB MakeNstring
emco = blankemco
emco.BlockNo = Nstring$
emco.Gcode = " 00": 'rapid traverse
emco.CNCx = OldCNCx
emco.CNCy = OldCNCy
emco.CNCz = " 00"
PRINT #2, emco.filler; emco.BlockNo; emco.Gcode; emco.CNCx; emco.CNCy; emco.CNCz; emco.Feed
' move to new location at rapid traverse
GOSUB MakeNstring
emco = blankemco
GOSUB ConvertP2G
emco.BlockNo = Nstring$
emco.Gcode = " 00": 'rapid traverse
emco.CNCz = " 00"
PRINT #2, emco.filler; emco.BlockNo; emco.Gcode; emco.CNCx; emco.CNCy; emco.CNCz; emco.Feed
' bring cutter down at proper feed rate at new location
GOSUB MakeNstring
emco.BlockNo = Nstring$
emco.Gcode = " 01": 'linear interpolation
emco.CNCz = clearence
emco.Feed = FeedRate
MID$(emco.CNCz, 1) = "-": '- to feed down
PRINT #2, emco.filler; emco.BlockNo; emco.Gcode; emco.CNCx; emco.CNCy; emco.CNCz; emco.Feed
RETURN
' ----------
' ----------
MillLine:
' mill line
GOSUB MakeNstring
emco = blankemco
GOSUB ConvertP2G
emco.CNCz = clearence
MID$(emco.CNCz, 1, 1) = "-"
emco.BlockNo = Nstring$
emco.Gcode = " 01": 'linear interp
emco.Feed = FeedRate
PRINT #2, emco.filler; emco.BlockNo; emco.Gcode; emco.CNCx; emco.CNCy; emco.CNCz; emco.Feed
RETURN
' ----------
ConvertP2G:
' converts adi plotter values to 1000's of inch for F1 controller
OldCNCx = emco.CNCx
OldCNCy = emco.CNCy
tempd = (px / ConversionFactor)
tempI = INT(tempd)
temp$ = ""
temp$ = STR$(tempI)
temp$ = RTRIM$(LTRIM$(temp$))
SELECT CASE LEN(temp$)
CASE IS = 1
temp$ = " " + temp$
CASE IS = 2
temp$ = " " + temp$
CASE IS = 3
temp$ = " " + temp$
CASE 4
temp$ = " " + temp$
CASE ELSE
temp$ = "~~~~~~"
END SELECT
emco.CNCx = temp$
tempd = (py / ConversionFactor)
tempI = INT(tempd)
temp$ = ""
temp$ = STR$(tempI)
temp$ = RTRIM$(LTRIM$(temp$))
SELECT CASE LEN(temp$)
CASE IS = 1
temp$ = " " + temp$
CASE IS = 2
temp$ = " " + temp$
CASE IS = 3
temp$ = " " + temp$
CASE 4
temp$ = " " + temp$
CASE ELSE
temp$ = "~~~~~"
END SELECT
emco.CNCy = temp$
RETURN